<template>
  <!--    <div>客户端档案挂接</div>-->
  <div class="app-container">

    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <fileTrees @handleNodeClick="onTreeClick" :tableHeight="treeHeight" :isnoClick="isnoClick" :menuId="menuId"></fileTrees>
      </el-col>
      <el-col :span="20" :xs="24" v-show="isShowTable">
        <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch"
                 label-width="68px">
          <el-form-item label="批次号" prop="batchNo">
            <el-input v-model="queryParams.batchNo" placeholder="请输入批次号" clearable/>
          </el-form-item>
          <el-form-item label="挂接时间" prop="dateRange">
              <el-date-picker
                v-model="dateRange"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
          </el-form-item>
          <el-form-item label="操作方式" prop="operationMode">
            <el-select v-model="queryParams.operationMode" placeholder="请选择" clearable>
              <el-option v-for="(dict, index) in operationType" :key="index" :label="dict.label"
                         :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search"  @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8" ref="refbut">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-folder-add"  @click="UnHookList">未挂接目录</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-document-add"  @click="hook">挂接</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="DataList" :height="tableHeight">
          <el-table-column label="挂接批次号" align="center" prop="batchNo"/>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button  type="text" @click="showLog(scope.row)">查看日志</el-button>
            </template>
          </el-table-column>
          <el-table-column label="挂接时间" prop="articulatedTime" align="center" />
          <el-table-column label="挂接结果" prop="articulatedResults" align="center" />
          <el-table-column label="重复数据操作方式" prop="operationMode" align="center" />
          <el-table-column label="操作人员" prop="createBy" align="center" />
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

    <!-- 未挂接目录弹窗 -->
    <el-dialog title="未挂接目录" :visible.sync="unHookOpen" width="50%" append-to-body>
      <div style="margin: 1%; padding-bottom: 1%">
      <el-table v-loading="unHookLoading" :data="unHooklist">
        <el-table-column label="序号" type="index" prop="id" />
        <el-table-column label="题名" prop="TITLE" :show-overflow-tooltip="true" />
        <el-table-column label="档号" prop="DH" :show-overflow-tooltip="true" />
        <el-table-column label="保管期限" prop="BGQX" :show-overflow-tooltip="true" />
        <el-table-column label="状态" prop="STATE" :show-overflow-tooltip="true" />
      </el-table>
      <pagination v-show="unHookTotal > 0" :total="unHookTotal" :page.sync="unHookParams.pageNum"
                  :limit.sync="unHookParams.pageSize" @pagination="getUnHookList" />
      </div>
    </el-dialog>

    <!-- 挂接弹窗 -->
    <el-dialog title="挂接" :visible.sync="hookOpen" width="60%" append-to-body>
      <div class="app-container">
        <el-form :model="hookParams" ref="hookParams" :rules="rules"  :inline="true" label-width="120px">
          <el-form-item label="重复数据校验" prop="repateOperationMode">
            <el-select v-model="hookParams.repateOperationMode" placeholder="请选择" clearable>
              <el-option v-for="(dict, index) in operationType" :key="index" :label="dict.label"
                         :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="档号字段" prop="fielNumberField">
            <el-select v-model="hookParams.fielNumberField" placeholder="请选择" clearable @change="getDefineOption()">
              <el-option v-for="dict in dhFieldOption" :key="dict.value" :label="dict.label"
                         :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="档号定义" prop="archivalCodeDefine">
            <el-select v-model="hookParams.archivalCodeDefine" placeholder="请选择" clearable>
              <el-option v-for="dict in dhDefineOption" :key="dict.value" :label="dict.label"
                         :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="文件类型" prop="fileType">
            <el-select v-model="hookParams.fileType" placeholder="请选择">
              <el-option v-for="item in dict.type.TYPE" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="挂接方式" prop="GJFS">
            <el-select v-model="hookParams.GJFS" placeholder="请选择">
              <el-option v-for="item in dict.type.GJFS" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="文件路径" prop="path">
            <!-- 上传按钮 -->
            <el-upload multiple action="" :http-request="uploadFileUrl" :before-upload="handleBeforeUpload" :file-list="fileList"
                       :on-error="handleUploadError" :on-exceed="handleExceed" :limit="1" :on-remove="handleRemove"
                       :show-file-list="true" :headers="headers" class="upload-file-uploader" ref="fileUpload" :data="uploadData">
              <el-button class="upload_btn" size="medium" type="primary" icon="el-icon-upload">上传文件</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="解压编码" prop="unZipCode">
            <el-select v-model="hookParams.unZipCode" placeholder="请选择">
              <el-option v-for="item in dict.type.JYBM" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
      </el-form>
      </div>
      <div class="table">
        <el-table v-loading="loading" :data="filedataList" height="300" style="overflow-y: auto">
          <el-table-column label="序号" type="index" width="55" align="center" prop="id"/>
          <el-table-column label="文件类型" prop="fileType" align="center" />
          <el-table-column label="文件名称" prop="fileName" align="center" />
          <el-table-column label="大小" prop="fileSize" align="center" />
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFile">保 存</el-button>
        <el-button @click="hookCancel">取 消</el-button>
      </div>
    </el-dialog>

    <showLog :logOpen="logOpen" :logLoading="logLoading" :logTotal="logTotal" :logList="logList" :logParams="logParams" @showLogCancel="showLogCancel" @getLogList="getLogList"></showLog>
  </div>
</template>
<script>
import CryptoJS from 'crypto-js';
import estimateTableHeight from '@/mixins/estimateTableHeight'
import treeHeight from '@/mixins/treeHeight'//计算左侧树的高度
import fileTrees from "@/components/fileTrees/index.vue"
import showLog from "@/views/archive/digitalizeReceive/clientArchiveHook/showLog"
import {
  getList,
  NotarticulatedList,
  getFileNumberField,
  getDefineList, articulatedLog, fileUpload, articulated
} from "@/api/archive/digitalizeReceive/clientArchiveHook";
import {getToken} from "@/utils/auth";
import axios from "axios";
import {getInfo} from "@/api/login";  //档案树
//vue项目中element-tabel自动计算高度
export default {
  mixins: [treeHeight, estimateTableHeight], // 混入方法
  archive_Dicts: ['TYPE', 'GJFS', 'JYBM', 'BGQX',"DA_STATE"],
  components: { fileTrees, showLog },
  data(){
    return{
      menuId: '',
      isnoClick:true,
      isClickSave:true,
      DataList: [],
      // 表格数据
      list: null,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      isShowTable: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        operationMode: undefined
      },
      dateRange: [],
      operationType: [
        {value: '1', label: '跳过'},
        {value: '2', label: '覆盖'},
        {value: '3', label: '追加'}
      ],

      stateOption: [
        {value: '1', label: '预归档-未接收'},
        {value: '2', label: '预归档-已接收'},
        {value: '3', label: '数字化成果未接收'},
        {value: '4', label: '归档审批中'},
        {value: '5', label: '已归档'},
        {value: '6', label: '移交审批中'},
        {value: '7', label: '已移交'},
      ],
      //未挂接目录弹窗
      unHookOpen: false,
      unHookLoading: true,
      unHookTotal: 0,
      unHookParams: {
        pageNum: 1,
        pageSize: 10,
        type:1,//按照配置未生效暂，定固定值
      },
      unHooklist: [],

      // 挂接弹窗
      hookOpen: false,
      hookLoading: true,
      hookTotal: 0,
      hooklist: [],
      hookParams: {
        repateOperationMode: undefined,
        fielNumberField: undefined,
        archivalCodeDefine: undefined,
        fileType: undefined,
        GJFS: undefined,
        unZipCode: 'GBK'
      },
      rules: {
        repateOperationMode: [
          { required: true, message: "重复数据操作方式不能为空" },
        ],
        fielNumberField: [
          { required: true, message: "档号字段不能为空" },
        ],
        archivalCodeDefine: [
          { required: true, message: "档号定义不能为空" },
        ],
        fileType: [
          { required: true, message: "文件类型不能为空" },
        ],
        GJFS: [
          { required: true, message: "挂接方式不能为空" },
        ]
      },
      // 获取档号字段下拉框
      dhFieldOption: [],
      // 获取档号定义下拉款
      dhDefineOption: [],

      // 上传文件表格数据
      filedataList: [],
      // 调用上传挂接包接口返回
      unZipPath: "",
      number: 0,
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      fileList: [],
      uploadList: [],
      uploadData: {},

      // 日志
      logOpen: false,
      logLoading: true,
      logTotal: 0,
      logList: [],
      logParams: {
        pageNum: 1,
        pageSize: 10,
      },
      limit: 1,
      chunkSize: '',
      userId: ''
    }
  },
  created() {
//this.$route.query.type  //判断   档案接收的客户端挂接type=0 还是档案管理的客户端挂接 type=1
    this.menuId = this.$route.meta.menuId
    this.getConfigKey("CHUNK_SIZE").then(response => {
      if(response.msg == '') {
        this.chunkSize = 20
      } else {
        this.chunkSize = response.msg
      }
    });
    getInfo().then(response=>{
      this.userId = response.user.userId
    })
  },
  methods: {
    // 树节点单击事件
    onTreeClick(data) {
      console.log(data)
      this.isnoClick=false;
      if (data.nodeType == null || data.nodeType == "t" || data.nodeType == "f") {
        this.isShowTable = false
        this.isnoClick=true;
        return;
      }
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        operationMode: undefined,
        articulatedTime: undefined,
        articulatedTimeTwo: undefined
      }
      this.dateRange = []
      this.isShowTable = true
      this.queryParams.categoryId = data.categoryId
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.getList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(this.dateRange != null) {
        if(this.dateRange.length != 0) {
          this.queryParams.articulatedTime = this.dateRange[0].toString()
          this.queryParams.articulatedTimeTwo = this.dateRange[1].toString()
        }
      }
      if(this.queryParams.batchNo != undefined && this.queryParams.batchNo != null && this.queryParams.batchNo != '') {
        const regex = /^[1-9]\d*$/;
        const isMatch = regex.test(this.queryParams.batchNo);
        if(isMatch == false) {
          this.$message({ message: '批次号请输入正整数', type: 'warning' })
          this.queryParams.batchNo = undefined
          return
        }
      }
      this.getList();
      this.queryParams.articulatedTime = ""
      this.queryParams.articulatedTimeTwo = ""
    },
    getList() {
      this.loading = true
      getList(this.queryParams).then(response=>{
        // console.log(response)
        this.total = response.total
        this.DataList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          for (let j = 0; j < this.operationType.length; j++) {
            if(response.rows[i].operationMode == this.operationType[j].value){
              this.DataList[i].operationMode = this.operationType[j].label
            }
          }
        }
        this.loading = false
        this.isnoClick=true;
      })
    },
    showLog(row) {
      this.logParams.id = row.id
      this.getLogList()
    },
    getLogList(logParams) {
      console.log(this.logParams,'========', logParams)
      if(logParams!=null && logParams!=undefined){
        this.logParams.pageNum = logParams.pageNum
        this.logParams.pageSize = logParams.pageSize
      } else {
        this.logParams.pageNum = 1
        this.logParams.pageSize = 10
      }
      articulatedLog(this.logParams).then(response=>{
        this.logLoading = false
        this.logList = response.rows
        this.logTotal = response.total
        this.logOpen = true
      })
    },
    showLogCancel() {
      this.logOpen = false
    },
    // 未挂接按钮
    UnHookList() {
      this.unHookParams = {
        pageNum: 1,
        pageSize: 10,
        type:1,//按照配置未生效暂，定固定值
      }
      this.unHookOpen = true
      this.getUnHookList()
    },
    getUnHookList() {
      this.unHookLoading = true
      this.unHookParams.categoryId = this.queryParams.categoryId
      console.log(this.$route.query.type ,"888888888888888888888888")
      //this.unHookParams.type = this.$route.query.type //判断   档案接收的客户端挂接type=0 还是档案管理的客户端挂接 type=1,此路由是在登陆sysadmin 里面 的菜单管理 下配置路由参数   {"type":1} 或者{"type":0}
      NotarticulatedList(this.unHookParams).then(response =>{
        this.unHookLoading = false
        this.unHooklist = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          console.log(this.dict.type.BGQX,this.dict.type.DA_STATE,)
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].BGQX == this.dict.type.BGQX[j].value){
              this.unHooklist[i].BGQX = this.dict.type.BGQX[j].label
            }
          }
          for (let j = 0; j < this.dict.type.DA_STATE.length; j++) {
            if(response.rows[i].STATE ==  this.dict.type.DA_STATE[j].value){
              this.unHooklist[i].STATE =  this.dict.type.DA_STATE[j].label
            }
          }
        }
        this.unHookTotal = response.total
      })
    },
    // 挂接按钮
    hook() {
      this.resetHook()
      this.getOption()
      this.hookOpen = true
    },
    resetHook() {
      this.resetForm("hookParams");
      this.hookParams = {
        repateOperationMode: undefined,
        fielNumberField: undefined,
        archivalCodeDefine: undefined,
        fileType: undefined,
        GJFS: 'NAME',
        unZipCode: 'GBK'
      }
      this.filedataList = []
      this.fileList = []
    },
    // 获取下拉款
    getOption() {
      this.form = {
        categoryId: this.queryParams.categoryId
      }
      getFileNumberField(this.form).then(response => {
        this.dhFieldOption = response.data.map(item => {
          return {
            value: item.fieldName,
            label: item.fieldCaption
          }
        })
      })
    },
    // 根据档号字段下拉获取档号定义下拉
    getDefineOption() {
      this.form = {
        categoryModelId: this.queryParams.categoryId,
        fColumnname: this.hookParams.fielNumberField
      }
      getDefineList(this.form).then(response => {
        this.dhDefineOption = response.rows.map(item => {
          return {
            value: item.id,
            label: item.name
          }
        })
      })
    },
    // 取消挂接弹窗
    hookCancel() {
      this.hookOpen = false
    },
    // 保存挂接
    submitFile() {
      this.$refs["hookParams"].validate(valid => {
          if (valid) {
            if(this.fileList.length == 0) {
              this.$message.warning("请上传挂接包")
              return
            }
            if (this.isClickSave){
              this.isClickSave = false;
              this.form = {
                repateOperationMode: this.hookParams.repateOperationMode,
                fielNumberField: this.hookParams.fielNumberField,
                archivalCodeDefine: this.hookParams.archivalCodeDefine,
                fileType: this.hookParams.fileType,
                GJFS: this.hookParams.GJFS,
                unZipPath: this.unZipPath,
                categoryId: this.queryParams.categoryId,
                typeState:1,//只能归档的挂接 暂时赋值1
              }
              articulated(this.form).then(response=>{
                this.$modal.msgSuccess(response.data)
                this.isClickSave = true;
                this.hookOpen = false
                this.getList()
              })
            }
          }
      })
    },
    // 上传前校检格式和大小
    handleBeforeUpload(file) {
      // if(this.hookParams.fielNumberField == undefined){
      //   this.$message.warning("档号字段不能为空")
      //   return false
      // }
      // if(this.hookParams.archivalCodeDefine == undefined){
      //   this.$message.warning("档号定义信息不能为空")
      //   return false
      // }
      // if(this.hookParams.fileType == undefined){
      //   this.$message.warning("文件类型不能为空")
      //   return false
      // }
      this.$refs["hookParams"].validate(valid => {
        if (valid) {
          // 校检文件类型
          const extension = file.name.substring(file.name.lastIndexOf('.') + 1);
          if (extension !== 'zip') {
            this.$message.warning('只允许上传zip格式的文件')
            return false
          }

          this.$modal.loading("正在上传文件，请稍候...");
          this.number++;
          return true;
        }
      })
    },
    calculateMD5(file) {
      return new Promise((resolve, reject) => {
        const chunkSize = 20 * 1024 * 1024;
        const totalChunks = Math.ceil(file.size / chunkSize); // 总块数
        let currentChunk = 0;
        const fileReader = new FileReader();
        const hashBuffer = [];
        fileReader.onload = function(event) {
          const chunkArray = new Uint8Array(event.target.result);
          hashBuffer.push(chunkArray);
          currentChunk++;
          if (currentChunk < totalChunks) {
            loadNextChunk();
          } else {
            const wordArray = CryptoJS.lib.WordArray.create(hashBuffer.reduce((acc, curr) => acc.concat(curr), []));
            const md5 = CryptoJS.MD5(wordArray).toString();
            file.md5 = md5; // 将计算得到的 MD5 值保存到 file 对象中
            resolve(md5);
          }
        };
        fileReader.onerror = function(event) {
          reject(event.target.error);
        };
        function loadNextChunk() {
          const start = currentChunk * chunkSize;
          const end = Math.min(start + chunkSize, file.size);
          fileReader.readAsArrayBuffer(file.slice(start, end));
        }
        loadNextChunk();
      });
    },
    // uploadFileUrl(concent, currentChunk) {
    //   console.log(concent)
    //   // 分片处理
    //   // const chunkSize = 20 * 1024 * 1024; // 每个片段的大小，这里是20MB
    //   concent.file.chunkSize = this.chunkSize;
    //   const totalChunks = Math.ceil(concent.file.size / (this.chunkSize * 1024 * 1024)); // 总片段数
    //   concent.file.chunks = totalChunks; // 将总片段数保存到file对象中
    //   let uploaded = 0 // 已上传块数
    //   let time1 = new Date().getTime();
    //   return this.calculateMD5(concent.file)
    //     .then(md5 => {
    //       let time2 = new Date().getTime();
    //       console.log("计算MD5耗时：",(time2-time1)+"毫秒");
    //       let time = new Date().getTime();
    //       let name2 = concent.file.name;
    //       let index = name2.lastIndexOf(".");
    //       name2 = name2.substring(0,index)+time+name2.substring(index,name2.length);
    //       // 将文件切分为多个片段
    //       const chunks = [];
    //       let time3 = new Date().getTime();
    //       for (let i = 0; i < totalChunks; i++) {
    //         const start = i * this.chunkSize * 1024 * 1024;
    //         const end = Math.min(start + this.chunkSize * 1024 * 1024, concent.file.size);
    //         // chunks.push(concent.file.slice(start, end));
    //         chunks.push(
    //           new Promise((resolve, reject) => {
    //             const formData = new FormData();
    //             formData.append("file", concent.file.slice(start, end),name2);
    //             formData.append("chunk", i + 1);
    //             formData.append("unZipCharSet", this.hookParams.unZipCode);
    //             formData.append("modeEnum", "RANDOM_ACCESS");
    //             //formData.append("chunkSize", concent.file.chunkSize); //分片大小
    //             formData.append("chunkSize", this.chunkSize); //分片大小
    //             formData.append("chunks", concent.file.chunks); // 总分片数
    //             //console.log(concent.file.chunkSize,"-----");
    //             //console.log(concent.file.chunks,"=====");
    //             formData.append("md5", md5); // md5值
    //             fileUpload(formData).then(response => {
    //               resolve(response); // 将上传结果传递给 Promise 的 resolve
    //             }).catch(error => {
    //               reject(error); // 将错误信息传递给 Promise 的 reject
    //             });
    //           })
    //         )
    //       }
    //       let time4 = new Date().getTime();
    //       console.log("文件上传耗时：",(time4-time3)+"毫秒");
    //       return Promise.all(chunks); // 等待所有分片上传完成
    //     })
    //     .then(responses => {
    //       console.log(responses,"+++");
    //       for (var k=0;k<responses.length;k++){
    //         let re = responses[k];
    //         if (re.data.fileInfos!=null && re.data.fileInfos!=undefined){
    //           this.handleUploadSuccess(re, concent.file);
    //         }
    //       }
    //     })
    //     .catch(error => {
    //       console.error("错误:", error);
    //       throw error; // 抛出错误，以便后续可以捕获并处理
    //     });
    // },
    uploadFileUrl(concent, currentChunk) {
      // 分片处理
      concent.file.chunkSize = this.chunkSize;
      const totalChunks = Math.ceil(concent.file.size / (this.chunkSize * 1024 * 1024)); // 总片段数
      concent.file.chunks = totalChunks; // 将总片段数保存到file对象中
      let uploaded = 0 // 已上传块数
      let time1 = new Date().getTime();
      let time = new Date().getTime();
      let name2 = concent.file.name;
      let index = name2.lastIndexOf(".");
      name2 = name2.substring(0,index)+time+name2.substring(index,name2.length);
      // 将文件切分为多个片段
      const chunks = [];
      let time3 = new Date().getTime();
      for (let i = 0; i < totalChunks; i++) {
        const start = i * this.chunkSize * 1024 * 1024;
        const end = Math.min(start + this.chunkSize * 1024 * 1024, concent.file.size);
        chunks.push(
          new Promise((resolve, reject) => {
            const formData = new FormData();
            formData.append("file", concent.file.slice(start, end),name2);
            formData.append("chunk", i + 1);
            formData.append("unZipCharSet", this.hookParams.unZipCode);
            formData.append("modeEnum", "RANDOM_ACCESS");
            formData.append("chunkSize", this.chunkSize); //分片大小
            formData.append("chunks", concent.file.chunks); // 总分片数
            formData.append("md5", this.userId + '_' + new Date().getTime()); // md5值，不再计算md5值
            console.log(this.userId + '_' + new Date().getTime())
            fileUpload(formData).then(response => {
              resolve(response); // 将上传结果传递给 Promise 的 resolve
            }).catch(error => {
              console.log(error,"shibai")
              reject(error); // 将错误信息传递给 Promise 的 reject
            });
          })
        )
      }
      let time4 = new Date().getTime();
      console.log("文件上传耗时：",(time4-time3)+"毫秒");
      return Promise.all(chunks) // 等待所有分片上传完成
        .then(responses => {
          console.log(responses,"+++");
          for (var k=0;k<responses.length;k++){
            let re = responses[k];
            if (re.data!=undefined && re.data.fileInfos!=undefined && re.data.fileInfos!=null ){
              this.handleUploadSuccess(re, concent.file);
            }
          }
        })
        .catch(error => {
          console.error("错误:", error);
          throw error; // 抛出错误，以便后续可以捕获并处理
        });
    },
    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传失败
    handleUploadError(err) {
      this.$modal.msgError("上传文件失败，请重试");
      this.$modal.closeLoading()
    },
    // 删除
    handleRemove(file, fileList) {
      this.fileList = []
      this.filedataList = []
    },
    // 上传成功回调
    handleUploadSuccess(res, file) {
        // 所有片段上传完成
        if (res.code === 200) {
          this.filedataList = res.data.fileInfos;
          this.unZipPath = res.data.unZipPath;
          this.uploadList.push(file);
          this.uploadedSuccessfully();
        } else {
          this.number--;
          this.$modal.closeLoading();
          this.$modal.msgError(res.msg);
          this.$refs.fileUpload.handleRemove(file);
          this.uploadedSuccessfully();
        }
    },
    // 上传结束处理
    uploadedSuccessfully() {
      if (this.number > 0 && this.uploadList.length === this.number) {
        this.fileList = this.fileList.concat(this.uploadList);
        this.uploadList = [];
        this.number = 0;
        this.$modal.closeLoading();
      }
    },
  }
}
</script>
